package com.xmb.wechat.view.alipay;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.xmb.wechat.R;
import com.xmb.wechat.R2;
import com.xmb.wechat.base.BaseActivity;
import com.xmb.wechat.widget.InputDialog;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @Author lijiangop
 * @CreateTime 2020/5/21 09:27
 */
public class AliPayBalanceDetailActivity extends BaseActivity {

    @BindView(R2.id.tv_money)
    TextView mTvMoney;

    public AliPayBalanceDetailActivity() {
        super(R.layout.activity_alipay_balance_detail);
        isChangeStatusBarTxtColor = false;
    }

    public static void start(Activity act, String money) {
        Intent it = new Intent(act, AliPayBalanceDetailActivity.class);
        it.putExtra("money", money);
        act.startActivity(it);
    }

    @Override
    protected void initView() {
        setStatusBarColor(Color.parseColor("#0f54af"));
        String money = getIntent().getStringExtra("money");
        Typeface fromAsset = Typeface.createFromAsset(getAssets(), "fonts/alipay_number.ttf");
        if (fromAsset != null)
            mTvMoney.setTypeface(fromAsset);
        mTvMoney.setText(money);
    }

    @OnClick({R2.id.tv_transfer_desc, R2.id.tv_zryeb_desc, R2.id.tv_jfb_desc, R2.id.tv_byj_desc})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.tv_transfer_desc) {
            showEditDialog(0, (TextView) view);
        } else if (id == R.id.tv_zryeb_desc) {
            showEditDialog(1, (TextView) view);
        } else if (id == R.id.tv_jfb_desc) {
            showEditDialog(2, (TextView) view);
        } else if (id == R.id.tv_byj_desc) {
            showEditDialog(3, (TextView) view);
        }
    }

    private void showEditDialog(int type, TextView view) {
        String title = "";
        switch (type) {
            case 0:
                title = "编辑转账备注信息";
                break;
            case 1:
                title = "编辑余额宝备注信息";
                break;
            case 2:
                title = "编辑集分宝备注信息";
                break;
            case 3:
                title = "编辑备用金备注信息";
                break;
        }
        InputDialog.showInputDialog(this, title, view.getText().toString().trim(), EditorInfo.TYPE_CLASS_TEXT, new InputDialog.OnInputDialogListener() {
            @Override
            public void onCancelClicked() {

            }

            @Override
            public void onOKClicked(Dialog dialog, String inputText) {
                try {
                    dialog.dismiss();
                    view.setText(inputText);
                } catch (Exception e) {
                    e.printStackTrace();
                    ToastUtils.showLong("输入格式错误！");
                }
            }
        });
    }
}
